﻿@{
    Layout = null;
}
@using AutoSchedule.Dtos.Models;
@model TaskPlan;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/css/layui.css" rel="stylesheet" />
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/layui.js"></script>

    <script src="~/js/bank.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>任务计划修改表单</legend>
    </fieldset>

    <form class="layui-form">

        <div class="layui-form-item" hidden="hidden">
            <label class="layui-form-label">GUID</label>
            <div class="layui-input-block">
                <input type="text" name="GUID" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.GUID">
            </div>
        </div>

        <div class="layui-form-item" hidden="hidden">
            <label class="layui-form-label">CODE</label>
            <div class="layui-input-block">
                <input type="text" name="CODE" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.CODE">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所属机构</label>
            <div class="layui-input-block">
                <select name="OrgCode" lay-filter="OrgCode" id="selectOrg">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">任务名称</label>
            <div class="layui-input-block">
                <input type="text" name="Name" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.Name">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">时间数</label>
            <div class="layui-input-block">
                <input type="text" name="Frequency" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.Frequency">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">时间类型</label>
            <div class="layui-input-block">
                <select name="FrequencyType" lay-filter="FrequencyType" id="FrequencyType">
                    <option value="0" selected>秒</option>
                    <option value="1" selected="">分</option>
                    <option value="2" selected="">时</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">数据接受类型</label>
            <div class="layui-input-block">
                <select name="WorkType" lay-filter="WorkType" id="WorkType">
                    <option value="0" selected>发送数据到dll</option>
                    <option value="1" selected="">发送数据到api</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Dll名称或Api地址</label>
            <div class="layui-input-block">
                <input type="text" name="DllOrUrl" lay-verify="required" autocomplete="off" placeholder="" class="layui-input" value="@Model.DllOrUrl">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-filter="enSure" lay-submit="">确定</button>
                <button type="reset" class="layui-btn" onclick="formClose()">取消</button>
            </div>
        </div>
    </form>

    <script type="text/javascript">

        $(function () {
            GetOrgList();
            $("#FrequencyType").val("@Model.FrequencyType");
             $("#selectOrg").val("@Model.OrgCode");
             $("#WorkType").val("@Model.WorkType");

        });
        function GetOrgList() {
            $.get("/Organization/OrgResult", function (data) {
                if (data.code == 0) {
                    var table = data.data;
                    for (var i = 0; i < table.length; i++) {
                        var item = table[i];
                        if ("@Html.Raw(Model.OrgCode)" == item.orgName) {
                             $("#selectOrg").append("<option value=\"" + item.orgNum + "\" selected>" + item.orgName + "</option>");
                        } else {
                            $("#selectOrg").append("<option value=\"" + item.orgNum + "\">" + item.orgName + "</option>");
                        }
                        
                    }
                    renderForm();
                }

                //返回的是json格式的数据
            }, "json");
           
        }
        function renderForm() {
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
        }

        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer;
            form.on('submit(enSure)', function (data) {
                var dataDetail = JSON.stringify(data.field);
                console.log(dataDetail);
                $.ajax({
                    url: "/TaskPlan/TaskPlanEdit",
                    async: true,
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=UTF-8",
                    data: dataDetail,
                    success: function (dataResult) {
                        if (dataResult.code != "0") {
                            alert(dataResult.msg);
                        } else {
                            alert(dataResult.msg);
                        }
                        var index = parent.layer.getFrameIndex(window.name);
                        setTimeout(function () { parent.layer.close(index) }, 1000);
                        setTimeout(function () { parent.location.reload() }, 100);
                    }
                });

            });
        });
    </script>
</body>
</html>